<?php
require_once "src/apiClient.php";
require_once "src/contrib/apiCalendarService.php";
session_start();
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Gmodeling extends CI_Controller {
function __construct()
    {
        parent::__construct();
    	$this->load->library('session');
		$this->load->helper('url');
    	$this->load->database();
    	$this->load->model("modelingmod");
    	
	}
	
/************* list *****************************/
function modelinglist()
{
	if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="model")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
					$listallreadypica=$this->modelingmod->allpicassaready();
					$listpgraph=$this->getnompgraph();
					$listmodelingassgined=$this->modelingmod-> allmodelingassigned($this->session->userdata("id"));
					$allmodelingfinished=$this->modelingmod->allmodelingfinished($this->session->userdata("id"));
					$data=array("listallreadypica"=>$listallreadypica,"listpgraph"=>$listpgraph,"listmodelingassgined"=>$listmodelingassgined
								,"allmodelingfinished"=>$allmodelingfinished);
					$this->load->view("modeling/listbymodeling",$data);	
											
			}
}


/*getnom photograph*/
function getnompgraph()
{
	$listreturn=array();
	$listpgraph=$this->modelingmod->getlistphotograph();
	foreach ($listpgraph as $pg)
	{
		$listreturn[$pg['iduser']]=$pg['name'].' '.$pg['lastname'];	
	}
	return $listreturn;
}


/******* changed status shooting*******/

function actionsgetmodeling()
{
		if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="model")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$idshooting=$this->input->get_post("idshooting");
				$idmoderateur=$this->session->userdata("id");
				$statusmodeling_idstatusmodeling=1;
				$data=array("shooting_idshooting"=>$idshooting,"statusmodeling_idstatusmodeling"=>$statusmodeling_idstatusmodeling,"idmoderateur"=>$idmoderateur);
				$idmodeling=$this->modelingmod-> insertetemplate("modeling",$data);	
				redirect("index.php?modeling/listbymodeling",'refresh');
			}	

}



/*editmodelingcontent*/
function getmcontent()
{
			if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="model")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$idmodeling=$this->input->get_post("idmodeling");
				$role=$this->input->get_post("role");
				$content=$this->modelingmod->getmodelingcontent($idmodeling);
				$modelingstatus=$this->modelingmod->getstatusmodeling();
				$data=array("content"=>$content,"modelingstatus"=>$modelingstatus,"role"=>$role);
				$this->load->view("modeling/mcontent",$data);
			}
			}


function submiteditcontent()
{
	
				if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="model")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$idmodeling=$this->input->get_post("idmodeling");
				$googleplus=$this->input->get_post("googleplus");
				$poi=$this->input->get_post("poi");
				$role=$this->input->get_post("role");
				//$urlvisite=$this->input->get_post("urlvisite");
				//$moderation=$this->input->get_post("moderation");
				//$facebook=$this->input->get_post("facebook");
				$commentaire=$this->input->get_post("commentaire");
				$statusmodeling_idstatusmodeling=$this->input->get_post("statusmodeling_idstatusmodeling");
				$data=array("googleplus"=>$googleplus,"poi"=>$poi,"commentaire"=>$commentaire,"statusmodeling_idstatusmodeling"=>$statusmodeling_idstatusmodeling);
				$udpate=$this->modelingmod->updatetemplate("modeling",$data,"idmodeling=$idmodeling");
				if($role=="admin"){redirect("index.php?gadmin/modelinglistadmin",'refresh');}else{
				redirect("index.php?gmodeling/modelinglist",'refresh');}
			}
	
}


function getmcontent2()
{
			if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="model")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$idmodeling=$this->input->get_post("idmodeling");
				$content=$this->modelingmod->getmodelingcontent($idmodeling);
				$modelingstatus=$this->modelingmod->getstatusmodeling();
				$role=$this->input->get_post("role");
				$data=array("content"=>$content,"modelingstatus"=>$modelingstatus,"role"=>$role);
				$this->load->view("modeling/mcontent2",$data);
			}
			}


function submiteditcontent2()
{
	
				if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="model")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$idmodeling=$this->input->get_post("idmodeling");
				//$googleplus=$this->input->get_post("googleplus");
				//$poi=$this->input->get_post("poi");
				$urlvisite=$this->input->get_post("urlvisite");
				$moderation=$this->input->get_post("moderation");
				$facebook=$this->input->get_post("facebook");
				$commentaire=$this->input->get_post("commentaire");
				$role=$this->input->get_post("role");
				//$statusmodeling_idstatusmodeling=$this->input->get_post("statusmodeling_idstatusmodeling");
				$data=array("urlvisite"=>$urlvisite,"moderation"=>$moderation,"facebook"=>$facebook,"commentaire"=>$commentaire);
				$udpate=$this->modelingmod->updatetemplate("modeling",$data,"idmodeling=$idmodeling");
				if($role=="admin"){redirect("index.php?gadmin/modelinglistadmin",'refresh');}else{
				redirect("index.php?gmodeling/modelinglist",'refresh');}
			}
	
}
/************* end list *****************************/


/*************************** Add ********************/

	function actionassingnephoto()
	{
		if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$idappointments=$this->input->get_post("idappointments");
				$role=$this->input->get_post("role");
				$idphotograph=$this->input->get_post("idphotograph");
				$data=array("User_idUser"=>$idphotograph,"statusshooting_idstatusshooting"=>1,"appointments_idappointments"=>$idappointments);
				$idinsert2=$this->Adminmod-> insertetemplate("shooting",$data);	
				redirect("index.php?gadmin/bookinglistadmin",'refresh');
				
			}
	}


	
	function editassingnephoto()
	{
		if($this->session->userdata("user")==false && $this->session->userdata("id")<=0&& $this->session->userdata("role")!="admin")
			{
					header('Location:index.php?pages/loginadmin');
						
			}else 
			{
				$idappointments=$this->input->get_post("idappointments");
				$role=$this->input->get_post("role");
				$idphotograph=$this->input->get_post("idphotograph");
				$idshooting=$this->input->get_post("idshooting");
				$data=array("User_idUser"=>$idphotograph);
				$idinsert2=$this->Adminmod-> updatetemplate("shooting",$data,"idshooting=$idshooting");
				redirect("index.php?gadmin/bookinglistadmin",'refresh');
			
			}
	}
/***************************** end Add ***************/

}//fin class